package com.project.web;

import com.project.pojo.Library;
import com.project.service.LibraryService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "DeleteByIdServlet", value = "/DeleteByIdServlet")
public class DeleteByIdServlet extends HttpServlet {
    private LibraryService libraryService = new LibraryService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        Library library = new Library();
        library.setBookId(Integer.parseInt(id));
        libraryService.deleteByid(library);
        List<Library> libraries = libraryService.selectAll();
        request.setAttribute("libraries",libraries);
        request.getRequestDispatcher("/library.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
